<?php

class Admin_ContactoController extends Zend_Controller_Action {

    private $_contactoModelo;

    public function init() {

        $this->_helper->layout->setLayout('admin');

        $this->view->headLink()->appendStylesheet('/css/layout.css');
        $this->view->headScript()->appendFile('/js/jquery-1.3.2.min.js');
        $this->view->headScript()->appendFile('/js/easyTooltip.js');
        $this->view->headScript()->appendFile('/js/jquery-ui-1.7.2.custom.min.js');

        $this->view->headScript()->appendFile('/js/hoverIntent.js');
        $this->view->headScript()->appendFile('/js/superfish.js');

        $this->view->headScript()->appendFile('/js/jquery.alerts.js');
        $this->view->headLink()->appendStylesheet('/css/jquery.alerts.css');

        $this->view->headScript()->appendFile('/js/jquery.filestyle.mini.js');
        $this->view->headScript()->appendFile('/js/custom.js');

        $this->_contactoModelo = new admin_Model_ContactoMapper();
    }

    public function preDispatch() {
        if (admin_Model_Login::isLoggedIn()) {
            $this->view->loggedIn = true;
            $this->_administrador = admin_Model_Login::getIdentity();
        } else {
            $this->_redirect('/admin/login/');
        }
    }

    public function indexAction() {
        $this->view->headTitle('Listado de Contactos');
        $this->view->titulo = 'Listado de Contactos';
        $this->view->contactos = $this->_contactoModelo->obtenerTodos();
        $this->view->administrador = $this->_administrador;
    }

    public function verAction() {
        $id = (int) $this->_request->getParam('id', 0);
        $this->view->headTitle('Información del Contacto');
        $this->view->titulo = 'Información del Contacto';
        $this->view->contacto = $this->_contactoModelo->obtenerPorId($id);
        ;
        $this->view->administrador = $this->_administrador;
    }

}

